package com.example.android.google;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

// currently unused since we could not get file storage and alarm manager working
//  quite right
public class AlarmReceiver extends BroadcastReceiver {
	/*
	 * private MediaPlayer mMediaPlayer; private static final long
	 * MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in // Meters private static
	 * final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in // Milliseconds
	 * 
	 * @Override public void onCreate(Bundle savedInstanceState) {
	 * super.onCreate(savedInstanceState); boolean alarm = false; int i=0; if
	 * (hasGPSDevice(this)) { Location curr_location = locationManager
	 * .getLastKnownLocation(LocationManager.GPS_PROVIDER); Location
	 * mark_location = new Location(curr_location);
	 * 
	 * // only if current location is within distance from marker for (i = 0; i
	 * < mio.size() && !alarm; i++) { // check distance double latitude =
	 * (double)(mio.createItem(i).getPoint() .getLatitudeE6()) / 1E6; double
	 * longitude = (double)(mio.createItem(i).getPoint() .getLongitudeE6()) /
	 * 1E6;
	 * 
	 * mark_location.setLatitude(latitude);
	 * mark_location.setLongitude(longitude); alarm =
	 * (mark_location.distanceTo(curr_location) < mio.createItem(i).getRange());
	 * } }
	 * 
	 * if (alarm && mio.createItem(i).getAlarm()) {
	 * this.requestWindowFeature(Window.FEATURE_NO_TITLE);
	 * this.getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
	 * WindowManager.LayoutParams.FLAG_FULLSCREEN);
	 * setContentView(R.layout.alarm);
	 * 
	 * Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
	 * stopAlarm.setOnTouchListener(new OnTouchListener() { public boolean
	 * onTouch(View arg0, MotionEvent arg1) { mMediaPlayer.stop(); finish();
	 * return false; } });
	 * 
	 * playSound(this, getAlarmUri()); }
	 * 
	 * Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 30);
	 * 
	 * Intent intent = new Intent(AlarmLocationActivity.this,
	 * AlarmReceiverActivity.class); PendingIntent pendingIntent =
	 * PendingIntent.getActivity( AlarmLocationActivity.this, 12345, intent,
	 * PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager)
	 * getSystemService(Activity.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,
	 * cal.getTimeInMillis(), pendingIntent); }
	 * 
	 * private void playSound(Context context, Uri alert) { mMediaPlayer = new
	 * MediaPlayer(); try { mMediaPlayer.setDataSource(context, alert); final
	 * AudioManager audioManager = (AudioManager) context
	 * .getSystemService(Context.AUDIO_SERVICE); if
	 * (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
	 * mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
	 * mMediaPlayer.prepare(); mMediaPlayer.start(); } } catch (IOException e) {
	 * System.out.println("OOPS"); } }
	 * 
	 * // Get an alarm sound. Try for an alarm. If none set, try notification,
	 * // Otherwise, ringtone. private Uri getAlarmUri() { Uri alert =
	 * RingtoneManager .getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert ==
	 * null) { alert = RingtoneManager
	 * .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) {
	 * alert = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_RINGTONE); }
	 * } return alert; }
	 */
	@Override
	public void onReceive(Context context, Intent intent) {
		// testing alarm manager
		Toast.makeText(context, "Alarm Called", Toast.LENGTH_SHORT).show();
	}
}
